package com.atguigu.phoenix.thin;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class PhoenixThinClientDemo {

    public static void main(String[] args) {
        testSelect();
    }

    /**
     * 查询  select
     */
    public static void testSelect(){
        try {
            Class.forName("org.apache.phoenix.queryserver.client.Driver");
            String url = "jdbc:phoenix:thin:url=http://hadoop102:8765;serialization=PROTOBUF" ;
            Connection connection = DriverManager.getConnection(url);
            String sql = "select id ,name ,addr from test1 where id = ? " ;
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1 , "1001");
            ResultSet resultSet = preparedStatement.executeQuery();
            if(resultSet.next()){
                String line = resultSet.getString("id") + " : " +
                        resultSet.getString("name") + " : " +
                        resultSet.getString("addr");
                System.out.println(line);
            }



        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            //关闭资源
        }
    }

    /**
     * 一个问题:  事务提交
     *        Mysql的事务默认是自动提交的
     *        Phoenix的事务默认不自动提交
     *
              connection.setAutoCommit();  //设置是否自动提交

              connection.commit(); // 提交

              connection.rollback(); // 回滚
     *
     * 新增、 修改   upsert
     */
    public static void testUpsert(){

    }

    /**
     * 删除  delete
     */
    public static void testDelete(){

    }
}
